package edu.nju.mutest.mutator;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.expr.*;
import edu.nju.mutest.util.CollectorUtil;
import edu.nju.mutest.visitor.collector.BasicTypeExpressionCollector;
import edu.nju.mutest.visitor.collector.cond.NumericCond;

import java.util.List;

public class AbsoluteValueInsertionMutator extends AbstractMutator {

    public AbsoluteValueInsertionMutator(CompilationUnit cu) {
        super(cu);
    }

    @Override
    public List<CompilationUnit> mutate() {
        if (mutPoints == null) {
            mutPoints = CollectorUtil.collect(new BasicTypeExpressionCollector(), origCU, new NumericCond());
        }

        for (Expression mp : mutPoints) {
            replaceNode(mp, new MethodCallExpr("Math.abs", mp.clone()));
            replaceNode(mp, new IntegerLiteralExpr("0"));
            replaceNode(mp, new UnaryExpr(new MethodCallExpr("Math.abs", mp.clone()), UnaryExpr.Operator.MINUS));
        }
        return mutants;
    }
}